import { IMG_PREFIX, LOGONAME} from './constant.js'
export const moneyToFixed =  (ov, digits) => {
  if (!ov) ov = 0;
  if (!digits) digits = 2;
  if (ov.toFixed) {
    return ov.toFixed(digits);
  } else {
    ov = parseFloat(ov);
    return ov.toFixed(digits);
  }
}

export const makeAbsoluteImageUrl = (ov) => {
  // 空直接返回logo
  if (!ov || ov == null) return `${IMG_PREFIX}/images/static/ZonesunMina/icon/${LOGONAME}`;
  if (ov.indexOf('http') != -1) {
    // http开头直接返回
    return ov;
  }
  return IMG_PREFIX + ov;
}

export const isGoodValid = (good) => {
  if (!good || !good.barcode) return false;
  if (good.status == 1 && (good.stock == null || good.stock > 0)) {
    return true;
  }
  return false;
}